# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=cpyrit-cuda
_pkgname=Pyrit
pkgver=0.5.0
pkgrel=3
pkgdesc="The famous WPA precomputed cracker for NVIDIA-CUDA."
url='https://github.com/JPaulMora/Pyrit'
license=('GPL3')
arch=('x86_64')
depends=('openssl' 'python2' 'zlib' 'libpcap' 'nvidia')
makedepends=('gcc' 'python2' 'cuda')
optdepends=(
  'scapy: packet capture analyzation support'
  'python2-sqlalchemy: storage support'
)
checkdepends=('python2-sqlalchemy' 'scapy')

checkdepends=('python2-sqlalchemy' 'scapy')
source=("$pkgname-$pkgver.tar.gz::https://github.com/JPaulMora/Pyrit/archive/v$pkgver.tar.gz"
        "scapy-2.3.2.patch"
	"fix-broken-join.patch")
sha512sums=('912742cd7d9cd9231b9b3aa155a5170c0ba36c3865280423e100c1d12df34e093ee56305d8738d4f406abbfef9b1d540872872b8ef23d699466298d41289ad25'
            '99d4ae2159be2d829337f3481cbb6580da1c6a2d2b6b28c7ed17348daa983859b7cd6ba3ee8575cbcba16efa27bf230bac075599b1fa0b531178dbdc45f853b2'
            '4a8d868a4adc94d5c6dd3c467572edd49efe0e0f4b0ea61ccfe830499e7cdedb0da81b27166caac23332fe90505fe0bbcfb67e61fde632cd58ce290e46426d67')


prepare() {
  cd $srcdir/$_pkgname-$pkgver

  # cpyrit CUDA module mod
  sed -i 's/ -ccbin clang / /' $srcdir/$_pkgname-$pkgver/modules/cpyrit_cuda/setup.py
  patch -p1 < "$srcdir/scapy-2.3.2.patch"
  patch -p1 < "$srcdir/fix-broken-join.patch"
  # Fix file cpyrit.py
  sed -i 's/CUDA =  cpyrit_cuda.listDevices()/CUDA = _cpyrit_cuda.listDevices()/;s/CUDA -= 1/#CUDA -= 1/' $srcdir/Pyrit-$pkgver/cpyrit/cpyrit.py
}

build() {
  # cpyrit CUDA module compile
  cd $srcdir/$_pkgname-$pkgver/modules/cpyrit_cuda
  python2 setup.py clean build

  # Pyrit compile
  cd $srcdir/$_pkgname-$pkgver
  python2 setup.py clean build
}

check() {
  cd $srcdir/$_pkgname-$pkgver/test
  local PYTHONVERSION="$(python2 -c 'import sys; print("{}.{}".format(sys.version_info.major, sys.version_info.minor))')"
  PYTHONPATH="../build/lib.linux-$CARCH-$PYTHONVERSION" \
    python2 test_pyrit.py
}

package() {
  cd $srcdir/Pyrit-$pkgver/modules/cpyrit_cuda
  python2 setup.py install -O1 --root="$pkgdir" --skip-build
  cd $srcdir/Pyrit-$pkgver
  python2 setup.py install -O1 --root="$pkgdir" --skip-build
  install -Dm 644 README.md CHANGELOG -t "$pkgdir/usr/share/doc/$pkgname"
}
